'use strict';

const Controller = require('egg').Controller;
const { ObjectId } = require("mongodb");

class SubjectController extends Controller {
    async index() {
        const { ctx } = this;
        const { id } = ctx.params;
        try {
            var db = this.app.mongodb;
            var res = await db.collection("article").find({ _id: ObjectId(id) }).toArray();
            ctx.body = {
                status: 200,
                res
            }
        } catch (err) {
            this.app.logger.error(err);
            ctx.status = 400;
            ctx.body = {
                status: 400,
                msg: "输入的id参数无效!"
            }
        }
    }
}

module.exports = SubjectController;
